<div class="layuimini-main" id="DeviceReport-search">
    <style>
        .status-black {
            margin-left: 10px;
            padding-left: 5px !important;
            padding-right: 5px !important;
            color: black;
        }
    </style>
    <form class="layui-form layui-form-pane" lay-filter="DeviceSoft_Detail_div_filter">
        <div class="layui-form-item">

            <label class="layui-form-label"> 设备名称</label>
            <div class="layui-input-block">
                <input type="text" maxlength="30"
                       name="DeviceName" autocomplete="off" class="layui-input"
                       placeholder="请输入设备名称" lay-reqText="请输入设备名称">
            </div>

        </div>
        <!--<div class="layui-form-item">

            <label class="layui-form-label"> 设备SN</label>
            <div class="layui-input-block">
                <input type="text" maxlength="16"
                       name="DeviceSN" autocomplete="off" class="layui-input"
                       lay-verify="required" placeholder="请输入设备SN" lay-reqText="请输入设备SN"
                       tipShow="1" tipMsg="设备SN,必填">
            </div>

        </div>-->
        <div class="layui-form-item">

            <label class="layui-form-label"> 设备IP</label>
            <div class="layui-input-block">
                <input type="text" maxlength="15"
                       name="IPAddress" autocomplete="off" class="layui-input"
                       lay-verify="required" placeholder="请输入设备IP" lay-reqText="请输入设备IP"
                       tipShow="1" tipMsg="设备IP,必填">
            </div>

        </div>
        <div class="layui-form-item">

            <label class="layui-form-label"> 设备端口</label>
            <div class="layui-input-block">
                <input type="text" maxlength="4"
                       name="Port" autocomplete="off" class="layui-input"
                       lay-verify="required" placeholder="请输入设备端口" lay-reqText="请输入设备端口"
                       tipShow="1" tipMsg="设备端口,必填">
            </div>

        </div>
        <div class="layui-form-item">

            <label class="layui-form-label"> Token</label>
            <div class="layui-input-block">
                <input type="text" maxlength="8"
                       name="Token" autocomplete="off" class="layui-input"
                       lay-verify="required" placeholder="请输入设备Token" lay-reqText="请输入设备Token"
                       tipShow="1" tipMsg="设备Token,必填">
            </div>

        </div>
        <div class="layui-form-item">
            <div class="layui-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="data-save-btn" id="btnAddDevice">添加</button>
            </div>
        </div>
    </form>

</div>
<script>

    layui.use(['form', 'upload', 'element', 'layer', 'faceAPI'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;
        var upload = layui.upload
            , element = layui.element
            , layer = layui.layer;
        var faceAPI = layui.faceAPI;

        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();
        // 当前弹出层，防止ID被覆盖
        var parentIndex = layer.index;

        form.on('submit(data-save-btn)', function (data) {
            var postdata = data.field;
            var index = layer.load(1, {
                shade: [0.5, '#fff'] //0.1透明度的白色背景
            });
            //  debugger
            faceAPI.Ajax({
                type: 'Post',
                data: postdata,
                url: '/api/FaceDeviceNew/AddDevice',
                success: function (result) {
                    if (result.result == false) {
                        layer.alert(result.error, { icon: 2 });
                    }
                    else {
                        faceAPI.FaceDeviceAddResult = result;
                        layer.close(parentIndex);
                    }
                    layer.close(index);
                }
            });
            return false;
        });

    });

</script>
